package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjCodeUserAddressChangeLog;
import com.zb.mapper.ZjCodeUserAddressChangeLogMapper;
import com.zb.result.PageUtil;
import com.zb.service.ZjCodeUserAddressChangeLogService;
import com.zb.vo.CodeRegisterAddressListVo;
import com.zb.vo.CodeUserRegisterVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 编码用户地址变更记录表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-09-28
 */
@Service
public class ZjCodeUserAddressChangeLogServiceImpl extends ServiceImpl<ZjCodeUserAddressChangeLogMapper, ZjCodeUserAddressChangeLog> implements ZjCodeUserAddressChangeLogService {

    // 获取变更用户登记地址列表
    @Override
    public Map<String, Object> getList(Long codeId, PageUtil pageUtil) {
        PageUtil.setPageLimit(pageUtil);
        QueryWrapper<ZjCodeUserAddressChangeLog> wrapper = new QueryWrapper<>();
        wrapper.select("id", "username", "phone", "province", "city", "area", "town", "address", "create_emp", "gmt_create");
        wrapper.eq("code_id", codeId);
        Page<ZjCodeUserAddressChangeLog> page = this.page(new Page<>(pageUtil.getPage(), pageUtil.getLimit()), wrapper);
        List<CodeRegisterAddressListVo> voList = page.getRecords().stream().map(log -> {
            CodeRegisterAddressListVo vo = new CodeRegisterAddressListVo();
            BeanUtils.copyProperties(log, vo);
            return vo;
        }).toList();
        return PageUtil.pageList(page.getCurrent(), page.getSize(), page.getTotal(), voList);
    }
}
